package Java7_Concurrency_Cookbook.thread_synchronized_base.condition;

/**
 * 消费者线程在 lines 条件上等待, 如果不满足条件, 消费者线程被挂起并释放锁</br>
 * 生产者线程在 space 条件上等待, 如果不满足条件, 生产者线程被挂起并释放锁</br>
 * @author lixiangke
 */
public class Main {
    public static void main(String[] args) {
        FileMock mock = new FileMock(100, 10);
        Buffer buffer = new Buffer(20);
        Producer producer = new Producer(mock, buffer);
        Thread threadProducer = new Thread(producer, "Producer");

        Consumer[] consumers = new Consumer[3];
        Thread threadConsumers[] = new Thread[3];
        for (int i = 0; i < 3; i++) {
            consumers[i] = new Consumer(buffer);
            threadConsumers[i] = new Thread(consumers[i], "Consumer" + i);
        }

        threadProducer.start();
        for (int i = 0; i < 3; i++) {
            threadConsumers[i].start();
        }
    }
}
